<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
</head>
<body>
  <div id="Application" style="text-align: center;">
    <h1>{{ title }}</h1>
    <div v-if="noLogin">
      账号：<input type="text" name="" id="" v-model="userName" />
    </div>
    <div v-if="noLogin">
      密码：<input type="password" name="" id="" v-model="password" />
    </div>
    <div v-on:click="click" style="border-radius: 30px; width: 100px; margin: 20px auto; color: white; background-color: blue;">{{ buttonTitle }}</div>
  </div>

  <script>
    const { createApp, ref } = Vue
    let config = {
      setup() {
        const title = ref('欢迎您：未登录')
        const noLogin = ref(true)
        const userName = ref('')
        const password = ref('')
        const buttonTitle = ref('登录')
        const click = () => {
          if (noLogin.value) {
            login()
          } else {
            logout()
          }
        }
        const login = () => {
          if (userName.value.length > 0 && password.value.length > 0) {
            alert(`userName: ${userName.value} password: ${password.value}`)
            noLogin.value = false
            title.value = `欢迎您：${userName.value}`
            buttonTitle.value = '注销'
            userName.value = ''
            password.value = ''
          } else {
            alert('请输入账号密码')
          }
        }
        const logout = () => {
          noLogin.value = true
          title.value = '欢迎您：未登录'
          buttonTitle.value = '登录'
        }
        return {
          title,
          noLogin,
          userName,
          password,
          buttonTitle,
          click
        }
      }
    }
    let app = createApp(config)
    app.mount('#Application')
  </script>
</body>
</html>